﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace MasterServer {
	public abstract class ServerProtocol : Protocol {
		internal TcpListener tcpListener;
		internal void StartListener() {
			tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8180);
			tcpListener.Start();
		}

		internal void AcceptSocket() {
			Socket socketForClient = tcpListener.AcceptSocket();
			if (socketForClient.Connected) {
				networkStream = new NetworkStream(socketForClient);
				streamWriter = new StreamWriter(networkStream);
				streamReader = new StreamReader(networkStream);
			}
		}
		
		internal override void Disconnect() {
			base.Disconnect();
			tcpListener.Stop();
		}
	}
}
